import type AbilityConstant from '@ohos.app.ability.AbilityConstant';
import hilog from '@ohos.hilog';
import UIAbility from '@ohos.app.ability.UIAbility';
import type Want from '@ohos.app.ability.Want';
import type window from '@ohos.window';
import PageBean from '../pages/PageBean';
import promptAction from '@ohos.promptAction';

/**
 * Lift cycle management of Ability.
 */
export default class AflameAbility extends UIAbility {
    private pageBean = new PageBean();

    getBean(): PageBean {
        return this.pageBean;
    }


    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        let eventhub = this.context.eventHub;
        // eventhub.on(WidgetMap.PAGE_INFO, (): PageBean  => {
        //     console.log("ddsds   111")
        //    return this.getBean()
        // })
        hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
    }

    onDestroy(): void {
        hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
    }

    onWindowStageCreate(windowStage: window.WindowStage): void {
        hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');

       /* sendPOST("adminApi.php?m=pages.getPageFrontEndByPageCode&system=pages&app=pages&v=1.0",
            {
                // "pageCode": "android_test_form"
                // "pageCode": "aokai_tab_manage_app"
                "pageCode": "aokai_main_task_myAll_app"
            },
        ).then(res => {
            if (res == null) {
                promptAction.showToast({
                    message: "页面错误",
                });
                return
            } else {
                Object.assign(this.pageBean, JSON.parse(res));
                hilog.info(0x0000, 'testTag', this.pageBean.pageType);
                // hilog.info(0x0000, 'testTag', this.pageBean.datasource[0].api);
                this.pageBean.sections.forEach(d => {
                    d.components.forEach(d2 => {
                        hilog.info(0x0000, 'testTag', d2.componentName + "   " + (d2.datasource.length)); //+ "   " + typeof d2.componentConfig);
                    })
                })
                globalThis.entryAbilityWant = this.pageBean;
                windowStage.loadContent("pages/AfalemePage", (err, data) => {
                });
            }
        }).catch(error => {
            console.error('HttpUtil2:' + error);
        });*/
    }


    loadData(windowStage: window.WindowStage) {
        windowStage.loadContent("pages/AfalemePage", (err, data) => {
        });
    }

    onWindowStageDestroy(): void {
        // Main window is destroyed, release UI related resources
        hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
    }

    onForeground(): void {
        // Ability has brought to foreground
        hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
    }

    onBackground(): void {
        // Ability has back to background
        hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
    }
}


// axios1("http://dev.lamiyun.com/adminApi.php?m=pages.getPageFrontEndByPageCode&system=pages&app=pages&v=1.0", "android_test_form");
// let context = this.context;
/**  context.resourceManager.getRawFileContent("android_test_form.json", (error, value) => {
 console.log("*****--------")
 if (error != null) {
 console.log(error.message)
 } else {
 console.log("*****--------" + value.byteLength)
 let f = StringUtils.uint8Array2String(value);
 let json1 = JSON.parse(f);
 let json2 = JSON.parse(json1.rst);
 Object.assign(this.pageBean, json2);
 hilog.info(0x0000, 'testTag', this.pageBean.pageType);
 hilog.info(0x0000, 'testTag', this.pageBean.datasource[0].api);
 this.pageBean.sections.forEach(d => {
 d.components.forEach(d2 => {
 hilog.info(0x0000, 'testTag', d2.componentName + "   " + d2.componentConfig);
 })
 })
 globalThis.entryAbilityWant = this.pageBean;
 windowStage.loadContent("pages/AfalemePage", (err, data) => {
 });
 }
 })**/